import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/layout/eg_Container.dart';

class EgCupertinoNavState extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return EgCupertinoNav();
  }
}

class EgCupertinoNav extends State<EgCupertinoNavState> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("主页")),
          BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text("聊天"))
        ],
        backgroundColor: CupertinoColors.lightBackgroundGray,
      ),
      tabBuilder: (context, index) {
        return CupertinoTabView(builder: (context) {
          switch (index) {
            case 0:
              return HomePage();
              break;
            case 1:
              return ChartPage();
              break;
            default:
              return Container();
          }
        });
      },
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Center(
          child: new SingleChildScrollView(
        child: Column(
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                Navigator.push(context, new MaterialPageRoute(builder: (context) {
                  return new EgContainer();
                }));
              },
              child: Text("跳转到Container演示页面", style: Theme.of(context).textTheme.button),
            ),
            Text("跳转到Container演示页面", style: Theme.of(context).textTheme.button),
          ],
        ),
      )),
      navigationBar: CupertinoNavigationBar(
        middle: Text("主页"),
      ),
    );
  }
}

class ChartPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Center(child: Text("聊天", style: Theme.of(context).textTheme.button)),
      navigationBar: CupertinoNavigationBar(
        middle: Text("聊天面板"),
        leading: Icon(CupertinoIcons.back),
        trailing: Icon(CupertinoIcons.add),
      ),
    );
  }
}
